package handlers

import (
	"jianianhua-server/database"
	"jianianhua-server/models"
	"jianianhua-server/utils"

	"github.com/gin-gonic/gin"
)

// GetUserSettings 获取用户设置字典
func GetUserSettings(c *gin.Context) {
	var settings models.UserSettings
	
	// 查询第一条记录（字典表只有一条记录）
	if err := database.DB.First(&settings).Error; err != nil {
		// 如果查询失败（表为空），返回默认设置
		settings = models.UserSettings{
			UserID:        0,
			PhoneHidden:   false,
			PerfectHidden: false,
			Setting1:      "完善资料",
			Setting2:      "",
			Setting3:      "",
		}
		// 尝试创建默认记录（不阻塞主流程）
		go func() {
			database.DB.FirstOrCreate(&settings, models.UserSettings{UserID: 0})
		}()
	}

	utils.SuccessResponse(c, settings)
}
